<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="sys.user.title" /></title>
  <meta name="decorator" content="list"/>
  <html:css name="iCheck,Validform,jquery-ztree,amaze-ui,easy-ui,layer"/>
  <link rel="stylesheet" type="text/css" href="${staticPath}/vendors/easy-ui/easyui.css">  
  <html:js name="iCheck,Validform,jquery-ztree,iframe,amaze-ui,public-js,layer"/>
  <script type="text/javascript" src="${staticPath }/uadmin/js/public-add.js"></script>
  <script type="text/javascript" src="${staticPath}/vendors/easy-ui/jquery.easyui.min.js"></script>
</head>
<body title="<spring:message code="sys.user.title" />">
    <div class="easyui-layout"  id="cc" style="width:100%;height: 800px;overflow-y:hidden;">
        
		<!-- 显示内容区域 -->
        <div data-options="region:'center'" style="overflow-y:hidden;width:82%;">
         <grid:grid id="userGridId" url="${adminPath}/sys/user/ajaxListUserByOrgpwd"  rowNum="200">
			<grid:column label="sys.common.key" hidden="true"   name="id" width="100"/>
		<%-- <grid:button groupname="opt" function="delete" url="${adminPath}/sys/user/{id}/deleteUser" /> --%>
			<grid:query name="orgId"  queryMode="hidden" />
				<grid:column  label="密码" name="password"  hidden="true"   query="true"  condition="like"/>
		    <grid:column label="sys.user.realname"  name="realname"   width="60" />
		    <grid:column label="sys.user.username"  name="username" width="60" />
		   <grid:column label="sys.user.phone"  name="phone"   width="60"/>
			 <grid:column label="冻结状态" name="status" width="60" dict="freezeStatus" align="center"/>
			 <grid:toolbar title="冻结" function="freeze" url="${adminPath}/sys/user/freeze"/>
                <grid:toolbar title="解冻" function="unfreeze" url="${adminPath}/sys/user/unfreeze"/>
                
                    <grid:toolbar title="重置密码" icon="fa-unlock-alt" function="defpassword"/>
               
			<grid:toolbar  function="search"/>
			<grid:toolbar title="重置" btnclass="btn-warning" layout="right"  icon="fa fa-refresh" function="dataReset('userGridIdGrid')"  />
		</grid:grid>
		</div>
    </div>
    <!-- 引入JX 模块公共js文件 -->
    <script type="text/javascript" src="${staticPath}/jx/jx_public.js"></script>
<script type="text/javascript">
var gridId = "userGridIdGrid";
function freeze(title, url, gridId, width, height) {
    var id = getSelectRows(gridId, false, false);
    var tipMsg = '你确定要冻结该用户么？';
    if (id) {
        url = url + '?userId=' + id;
        rowConfirm(title, url, id, gridId, tipMsg);
    }
}

function unfreeze(title, url, gridId, width, height) {
    var id = getSelectRows(gridId, false, false);
    var tipMsg = '你确定要解冻该用户么？';
    if (id) {
        url = url + '?userId=' + id;
        rowConfirm(title, url, id, gridId, tipMsg);
    }
}

function unlock(title, url, gridId, width, height) {
    var id = getSelectRows(gridId, false, false);
    var tipMsg = '你确定要解锁该用户么？';
    if (id) {
        url = url + '?userId=' + id;
        rowConfirm(title, url, id, gridId, tipMsg);
    }
}
function defpassword() {

    var ids = getSelectRows(gridId, true, false);
    if (!ids) {
		layer.msg('至少选择一条记录!!!',{icon:3});
        return;
    }
    var url = "${adminPath}/sys/user/resetChangePassword";
    layer.confirm("请您确定要重置【" + ids.length + " 个用户】的密码吗?请谨慎操作！", {
        title: "提示",
        icon: 3,
        btn: ['确定', '取消'] //按钮
    }, function () {
        //确定
        $.ajax({
            url: url,
            type: 'post',
            data: {
                ids: ids.join(',')
            },
            success: function (d) {
                var msg = d.msg;
                layer.msg(msg, {icon: 3, shade: 0.3, time: 1000});
            },
            error:function (errorData) {
                console.log(errorData);
                layer.msg("重置失败", {icon: 3, shade: 0.3, time: 1000});
            }
        });
    }, function () {
        //取消
    });
} 


	var treeObj;
	var node = undefined;
	$(function(){
		treeObj=$.fn.zTree.init($("#treeObj"), setting);
	});
	/**初始化树节方法*/
	var setting = {
			async: {
				enable: true,
				url:"${adminPath}/sys/organization/selectOrgData",
				autoParam:["id=nodeId"],
				dataFilter: filter
			},
			callback: {
				onClick: onClick
			}
		};

	function filter(treeId, parentNode, childNodes) {
		if (!childNodes) return null;
		for (var i=0, l=childNodes.length; i<l; i++) {
			childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
		}
		return childNodes;
	}
	
	function onClick(event, treeId, treeNode, clickFlag) {
		 node = treeNode;
		 $("input[name='orgId']").val(treeNode.id);
	     search('userGridIdGrid');
	}
	function getSelectRows(gridId,isMulti,returnRow){
		var ids  = $("#"+gridId).jqGrid('getGridParam','selarrrow');
		var multiselect = $("#"+gridId).jqGrid('getGridParam','multiselect');
		var id = $("#"+gridId).jqGrid('getGridParam','selrow');
		if(!multiselect){
			if(id){
				ids[0]=id;
			}
		}
	    if (!id || ids.length==0) {
		    layer.msg('请至少选择一条数据!', {icon: 0, time: 1000});
			return; 
		}
	    if (!isMulti&&ids.length>1) {
	    	layer.msg('只能选择一条数据!', {icon: 0, time: 1000});
			return;
		}
	    var row = $("#"+gridId).jqGrid('getRowData',id);
	    if(isMulti){
	    	if(returnRow){
	    		return getRows(gridId,ids);
	    	}else{
	    		return ids;
	    	}
	    }else{
	    	if(returnRow){
	    		return row;
	    	}else{
	    		return id;
	    	}
	    }
	}
</script>
</body>
</html>